<?php
$title="Tagboard";
include('top.php');

echo '<p align="center">
		<a href="index.php"> [Version Normal]</a></p>';


if(isset($_POST['nombre']) && !empty($_POST['nombre']) && isset($_POST['text']) && !empty($_POST['text']))
{
  $_POST['text']=nl2br($_POST['text']);
  $_POST['text']=addslashes($_POST['text']);
  $link=Conectarse();   	
	mysql_query ("INSERT INTO POST (NOMBRE, TEXTO, FECHA) VALUES ('{$_POST['nombre']}', '{$_POST['text']}', '".date('d/m/Y H:i')."')",$link);
	mysql_close($link);
}elseif(isset($_POST['nombre']) || !empty($_POST['nombre']) || isset($_POST['text']) || !empty($_POST['text']))
{
  echo "Error, introduce todos los valores.";
}
$pag=0;
$link=conectarse();
$result = mysql_query ("SELECT * FROM POST",$link);
while ($row = mysql_fetch_array ($result))
{
$pag++;	
}
$pag=$pag/5;
$pag=(int)$pag;
$pag++;
if(isset($_GET['Pag'])){$min=($_GET['Pag']*5)-5;}
else{
$min=0;
}
mysql_free_result($result);
mysql_close($link);
$link=conectarse();
$result = mysql_query ("SELECT * FROM POST ORDER BY ID_POST DESC LIMIT ".$min." , 5",$link);		
echo '  <table width="500" border="0" align="center">
<tr>
	<td>';
$cont=0;
while ($row = mysql_fetch_array ($result))
{
echo '<table width="100%" border="0" align="center" bgcolor="'; if ($cont%2==0){echo '#FFFF99';}else{echo '#FFFF66';} echo '" cellpadding="2">
		<tr>
   			<td width="100"><strong>'.$row['NOMBRE'].'</strong></td>
  			<td><font color=RED>';if($cont=="0"){echo 'Nuevo!';}echo'</font></td>
  			<td align="right" bordercolor="'; if ($cont%2==0){echo '#FFFF99';}else{echo '#FFFF66';} echo '">'.$row['FECHA'].'</td>
	 	</tr>
		<tr>
    			<td colspan="3" style="height:2px;background-color:#f6a504;"></td>
    		</tr>
    			<td bordercolor="#'; if ($cont%2==0){echo '#FFFF99';}else{echo '#FFFF66';} echo '" colspan="3" height="100" valign="top"><p>'.stripcslashes($row['TEXTO']).'</p></td>
    		</tr>	
		</table>
		<table width="100%" border="0" align="center">
  		<tr>
    			<td colspan="3" style="height:2px;background-color:#C7C7C7;"></td>
    		</tr>	
		</table>';
$cont++;	
}
mysql_free_result($result);
mysql_close($link);
echo '<table width="100%">
<tr>
<td align="right">';
$pass=0;
$pass2=0;
$pass3=0;
$con=0;
for($i=1;$i<=$pag;$i++)
{

if ($con=="6"){if ($i!=$pag){echo " ... ";}$i=$pag;}

if (!isset($_GET['Pag']) || $_GET['Pag']==1){$pass3=1;}

if (!isset($_GET['Pag']) && $pass2=="0"){
echo $i.' ';
$pass2=1;
}
elseif(isset($_GET['Pag']) && $_GET['Pag']==$i){
  
  echo $i.' ';
} 
else{
  if($i!="1" && $pass3=="0" && $_GET['Pag']>"4"){echo '... ';$pass3=1;}
echo '<a href="'.$_SERVER['PHP_SELF'].'?Pag='.$i.'">'.$i.'</a> ';}
if (isset($_GET['Pag']) && $_GET['Pag']>3 && $pass==0){$i=$_GET['Pag']-3;$pass=1;}
$con++;
}
echo '</td>
</tr>
</table></td>
</tr>
</table>';
echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="post">
<table align="center">
<tr>
	<td>Nombre:</td>
</tr>
<tr>
	<td><input type="text" name="nombre" value="';if(isset($_POST['nombre'])){echo $_POST['nombre'];}echo'"></td>
</tr>';
?>
<script>
function maximaLongitud(texto,maxlong) {
var tecla, in_value, out_value;

if (texto.value.length > maxlong) {
in_value = texto.value;
out_value = in_value.substring(0,maxlong);
texto.value = out_value;
return false;
}
return true;
}
</script>
<?php
echo  '<tr>
	<td>Post:</td>
</tr>
<tr>
	<td><textarea rows="10" cols="40" name="text" onKeyUp="return maximaLongitud(this,5000)">';if(isset($_POST['nombre'])){echo $_POST['text'];}echo'</textarea></td>
</tr>
<tr>
	<td><input type="hidden" name="crear" value="1">
	<input type="submit" name="submit" value="Postear">
</tr>	
</table>
</form>';

// boton de volver no!

$back=0;
include('down.php');	
?>